package com.base.gram;

import com.alibaba.fastjson.JSONObject;

import java.util.Calendar;
import java.util.Date;

/**
 * create by yongli on 2021-09-07 19:00
 */

public class TimeCalculate {
    public static void main(String[] args) {
        Date date =new Date();
        System.out.println(date);

        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar);


        JSONObject entity = new JSONObject();
        entity.put("date",date);
        entity.put("calendar",calendar);
        // 默认的date都会转换为long型数字
        System.out.println(entity.toJSONString());

        long test = date.getTime();
        long test2 = calendar.getTimeInMillis();

        calendar.add(Calendar.MONTH,-2);
        System.out.println(calendar.getTime());

        calendar.add(Calendar.MONTH,-121);
        System.out.println(calendar.getTime());

        calendar.setTime(date);
        // day of week：星期几, 从sunday开始，1，2，3，4
        System.out.println(calendar.get(Calendar.DAY_OF_WEEK));

        System.out.println(System.currentTimeMillis());

    }
}
